package com.sh.data.engine.domain.api.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sh.data.engine.domain.api.model.domain.DataApiDomain;
import com.sh.data.engine.domain.api.model.domain.DataApiLogDomain;
import com.sh.data.engine.domain.api.model.domain.DataApiMyApiDomain;
import com.sh.data.engine.domain.api.model.domain.rest.DataApiBaseDomain;
import com.sh.data.engine.domain.api.model.domain.rest.DataApiConfigInfoDomain;
import com.sh.data.engine.domain.api.model.domain.rest.DataApiTaskParamDomain;
import com.sh.data.engine.domain.api.model.param.DataApiBaseParam;
import com.sh.data.engine.domain.api.model.param.DataApiExampleTestParam;
import com.sh.data.engine.domain.api.model.param.DataApiMyApiParam;
import com.sh.data.engine.domain.api.model.param.DataApiRegisterParam;
import com.sh.data.engine.repository.dao.api.entity.DataApiEntity;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;
import java.util.Map;

/**
 * @author : fuchen
 * @date : 2022/1/19 15:31
 * <p>API元数据和APi信息
 */
public interface DataApiService extends IService<DataApiEntity> {

    boolean publishApiById(Long id);

    boolean publishApiByIds(List<Long> ids);

    boolean cancalPublishApiById(Long id);

    String cancalPublishApiInfoById(Long id);

    boolean cancalPublishApiByIds(List<Long> id);

    boolean saveApi(DataApiBaseParam dataApiBaseParam);

    boolean saveRegisterApi(DataApiRegisterParam dataApiRegisterParam);

    Map<Long, DataApiEntity> getApiPathMap(List<Long> ids);

    DataApiDomain findDataApiById(Long id);

    IPage<DataApiMyApiDomain> findMyDataApiListByIds(
        DataApiMyApiParam dataApiMyApiParam, String username, List<Long> ids);

    IPage<DataApiMyApiDomain> findMyDataApiList(
        DataApiMyApiParam dataApiMyApiParam, String username, List<Long> groupIds);

    boolean removeDataApiById(Long id);

    DataApiConfigInfoDomain getDataApiConfig(Long id);

    DataApiConfigInfoDomain getDataApiConfigInfoByType(
        DataApiConfigInfoDomain dataApiConfigInfoDomain, DataApiDomain dataApiDomain);

    /**
     * api 详情
     */
    DataApiDomain getDataApiDetailById(Long id);

    IPage<DataApiBaseDomain> getMarketApiList(
        Long projectId,
        List<Long> groupId,
        String apiName,
        Integer pageNum,
        Integer pageSize,
        String userId);

    List<DataApiEntity> getAllPublishedApiList(Long projectId);

    List<DataApiBaseDomain> getApiList(Long projectId, Long dirId);

    Long getTotalApiSumByProjectAndUserId(Long projectId, String userId);

    Long getTotalApiByProjectId(Long projectId);

    Long getTotalPublishedApiByProjectId(Long projectId);

    Long getTotalFailApiByProjectId(Long projectId);

    List<DataApiDomain> getApiUsedTop(Long projectId, Integer reqStatus, String userId);

    Long testApi(DataApiBaseParam dataApiBaseParam, Long projectId);

    DataApiLogDomain getRequestTestLog(Long logId, Integer offset);

    DataApiLogDomain getRequestLog(Long logId, Integer offset);

    String getResponseExample(DataApiExampleTestParam dataApiGuideTestParam);

    Long testApi(Long apiId, HttpServletRequest request, Long projectId);

    Long testApiAbacus(Long apiId, Map<String, String> params, Long projectId);

    void exportApi(List<Long> ids, String userId, Long projectId, HttpServletResponse response);

    List<DataApiTaskParamDomain> getParams(String sql, Long dsId);

    List<DataApiTaskParamDomain> getTestInfo(Long apiId);

    /**
     * @description : 找到跟指标关联的数据服务
     * @author : tinglan.ys
     * @date : 2022/5/13
     */
    List<DataApiEntity> findByProjectIdIndexId(Long projectId, Long indexId);

    Boolean deleteDir(Long id);

    Long testRegisterApi(DataApiRegisterParam dataApiRegisterParam);

    List<DataApiConfigInfoDomain> getDataApiConfigs(Integer total);

    List<DataApiEntity> getListByPage(Long projectId, Integer pageSize, Integer pageNum);

    boolean resetUserToken(String password);

    List<String> getNodeTableById(Long jobId);
}
